using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using AdminSG3L.Applicaticn.ServicesInterface;
using AdminSG3L.Applicaticn.Dtos;
using AdminSG3L.Applicaticn.Commands;

namespace AdminSG3L.Api.Controllers;

/// <summary>
/// 系统管理控制器
/// </summary>
[ApiController]
[Route("api/[controller]")]
[Authorize]
public class SystemController(ISystemService systemService) : ControllerBase
{
    private readonly ISystemService _systemService = systemService;

    /// <summary>
    /// 获取系统信息
    /// </summary>
    [HttpGet("info")]
    public async Task<ApiResponse<SystemInfoDto>> GetSystemInfo()
    {
        return await _systemService.GetSystemInfoAsync();
    }

    /// <summary>
    /// 获取系统配置
    /// </summary>
    [HttpGet("config")]
    public async Task<ApiResponse<Dictionary<string, object>>> GetSystemConfig()
    {
        return await _systemService.GetSystemConfigAsync();
    }

    /// <summary>
    /// 更新系统配置
    /// </summary>
    [HttpPut("config")]
    public async Task<ApiResponse<bool>> UpdateSystemConfig([FromBody] Dictionary<string, object> config)
    {
        return await _systemService.UpdateSystemConfigAsync(config);
    }

    /// <summary>
    /// 获取系统日志
    /// </summary>
    [HttpGet("logs")]
    public async Task<ApiResponse<PagedResult<SystemLogDto>>> GetSystemLogs(
        [FromQuery] int page = 1, 
        [FromQuery] int size = 10)
    {
        return await _systemService.GetSystemLogsAsync(page, size);
    }

    /// <summary>
    /// 清理系统缓存
    /// </summary>
    [HttpPost("cache/clear")]
    public async Task<ApiResponse<bool>> ClearCache()
    {
        return await _systemService.ClearCacheAsync();
    }

    /// <summary>
    /// 获取系统性能指标
    /// </summary>
    [HttpGet("performance")]
    public async Task<ApiResponse<SystemPerformanceDto>> GetPerformanceMetrics()
    {
        return await _systemService.GetPerformanceMetricsAsync();
    }

    /// <summary>
    /// 系统健康检查
    /// </summary>
    [HttpGet("health")]
    public async Task<ApiResponse<HealthCheckDto>> HealthCheck()
    {
        return await _systemService.HealthCheckAsync();
    }
}